﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using QinTools.View;
using QinTools.Model.Characters;

namespace QinTools.ViewModel.Documents
{
    public class CharacterDocument : Document
    {
        public Character CharacterModel { get; private set; }

        public CharacterViewModel ViewModel { get; set; }

        public CharacterDocument(CharacterViewModel viewModel) : base(viewModel.Model)
        {
            CharacterModel = viewModel.Model;
            CharacterModel.PropertyChanged += new PropertyChangedEventHandler(CharacterModel_PropertyChanged);
        }

        private void CharacterModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Name")
            {
                var title = CharacterModel.Name;
                if (string.IsNullOrWhiteSpace(title))
                {
                    title = DocumentRepository.Instance.GetNewTitle("Character");
                }
                Title = title;
            }
        }

        public override void DocumentClosed()
        {
            //TODO: Prompt for saving if model is dirty. 
        }
    }
}
